package com.adison.performancedemo.ui;

import com.adison.performancedemo.R;
import com.bumptech.glide.Glide;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by adison on 15/11/16.
 */
public class UIRecycllerAdapter extends RecyclerView.Adapter<UIRecycllerAdapter.ViewHolder>  {

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        Context context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);

        View contactView = inflater.inflate(R.layout.item_hierachy, parent, false);

        return new ViewHolder(contactView);
    }

    @Override
    public void onBindViewHolder(UIRecycllerAdapter.ViewHolder holder, int position) {
        TextView textView = holder.nameTextView;
        ImageView contactPic = holder.imageView;

        textView.setText("测试["+position+"]");
        Glide.with(contactPic.getContext())
                .load(R.drawable.test_pic)
                .fitCenter()
                .into(contactPic);
    }


    @Override
    public int getItemCount() {
        return 1000;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{

        public TextView nameTextView;

        public ImageView imageView;

        public ViewHolder(View itemView) {
            super(itemView);
            nameTextView = (TextView) itemView.findViewById(R.id.item_name);
            imageView = (ImageView) itemView.findViewById(R.id.item_image);
        }
    }

}
